package win.smartown.android.library.scrollpager.impl;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ListView;

import win.smartown.android.library.scrollpager.interfaces.Scrollable;

/**
 * Created by Smartown on 2017/9/25.
 */
public class ScrollableListView extends ListView implements Scrollable {
    public ScrollableListView(Context context) {
        super(context);
    }

    public ScrollableListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ScrollableListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public ScrollableListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public boolean atTop() {
        View firstView = getChildAt(0);
        return firstView == null || firstView.getTop() == 0;
    }

    @Override
    public boolean atBottom() {
        return getLastVisiblePosition() == getAdapter().getCount() - 1
                && getHeight() >= (getChildAt(getLastVisiblePosition() - getFirstVisiblePosition()).getBottom());
    }

    @Override
    public void onScroll() {

    }
}
